package ${package.ServiceImpl};

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sieiot.goodknow.base.stable.api.PageQO;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Override
    public boolean insert(${entity} ${entity?uncap_first}) {
        return this.save(${entity?uncap_first});
    }

    @Override
    public boolean update(${entity} ${entity?uncap_first}) {
        return this.update(${entity?uncap_first});
    }

    @Override
    public boolean deleteById(Long id) {
        return this.removeById(id);
    }

    @Override
    public ${entity} queryById(Long id) {
        return this.getById(id);
    }

    @Override
    public List<${entity}> queryByIds(List<Long> idList) {
        // 空列表时会有异常
        List<Long> list = null;
        if (idList != null && !idList.isEmpty()) {
            // 去重，能保持元素顺序
            list = idList.stream().distinct().collect(Collectors.toList());
        }
        return baseMapper.queryByIds(list);
    }

    @Override
    public Page<${entity}> pageQuery(PageQO<${entity}> pageQO) {
       Page<${entity}> page = PageHelper.startPage(pageQO.getPageNum(),
               pageQO.getPageSize(), true);
       this.baseMapper.queryList(pageQO.getQuerys());
       return page;
    }

}
</#if>
